package com.bw.finance.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.bw.finance.conf.ResponseResult;
import com.bw.finance.eneity.cms.EduWebsiteAd;
import com.bw.finance.eneity.cms.EduWebsitePage;
import com.bw.finance.eneity.cms.EduWebsiteTemplate;
import com.bw.finance.service.IEduWebsitePageService;
import com.bw.finance.utils.PhotoUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author zxx
 * @since 2020-08-16
 */
@RestController
@RequestMapping("/wbpage")
public class EduWebsitePageController {
    @Autowired
    private IEduWebsitePageService pageService;

    private static final Logger log= LoggerFactory.getLogger(EduWebsiteAdController.class);

    @PostMapping("/wbpagelist")
    public ResponseResult adlist(@RequestBody EduWebsitePage websitePage){
        log.info("页面信息查询开始");
        ResponseResult result = ResponseResult.SUCCESS();
        try {
            Map map=new HashMap();
            if(websitePage.getPageName()!=null){
                map.put("pageName",websitePage.getPageName());
            }
            List<EduWebsitePage> list=pageService.findlist(map);
            result.setResult(list);
        }catch (Exception e){
            log.error("页面信息查询异常"+e.toString());
            result.setSuccess(false);
            result.setMessage("页面信息查询异常"+e.toString());
        }
        log.info("页面信息查询结束");
        return result;
    }

    @PostMapping("/addpage")
    public ResponseResult addpage(@RequestBody EduWebsitePage websitePage){
        log.info("页面添加开始");
        ResponseResult result = ResponseResult.SUCCESS();
        try {
            websitePage.setCreateTime(new Date());
            pageService.saveOrUpdate(websitePage);
            result.setMessage("保存成功！！！！");
        }catch (Exception e){
            log.error("页面添加异常"+e.toString());
            result.setSuccess(false);
            result.setMessage("添加异常"+e.toString());
        }
        log.info("页面添加结束");
        return result;
    }

    @GetMapping("/page/{id}")
    public ResponseResult addpage(@PathVariable Long id, HttpServletResponse response){
        log.info("页面发布开始");
        ResponseResult result = ResponseResult.SUCCESS();
        try {
            result=pageService.addpage(id,response);
            result.setMessage("发布成功！！！！");
        }catch (Exception e){
            log.error("页面发布异常"+e.toString());
            result.setSuccess(false);
            result.setMessage("发布异常"+e.toString());
        }
        log.info("页面发布结束");
        return result;
    }
}
